#include <vector>
#include <string>
#include <unordered_set>

using namespace std;


class Solution {
public:

    // 467. 环绕字符串中唯一的子字符串
    // https://leetcode.cn/problems/unique-substrings-in-wraparound-string/
    int findSubstringInWraproundString(string s) {
        int n = s.size();
        vector<int> dp(n, 1);
        int hash[26] = { 0 };
        hash[s[0]-'a'] = 1;

        for (int i = 1; i<n; ++i)
        {
            if (s[i-1] + 1 == s[i] || (s[i-1] == 'z' && s[i] == 'a'))
            {
                dp[i] += dp[i-1];
            }
            hash[s[i]-'a'] = max(hash[s[i]-'a'], dp[i]);
        }

        int ans = 0;
        for (int i = 0; i<26; ++i)
            ans += hash[i];

        return ans;
    }
};